<?php include_once './application/views/sys_admin/common/header.php';  ?>
<?php 
	$typearr = array(1=>'首页',2=>'注册',3=>'活动注册');
?>
<?php if(isset($admin['type_id']) && $admin['type_id'] !=1){?>
<h3 style="color:red">对不起，权限不足</h3>
<?php }else{?>
<div class=" definewidth m20">
		<form  class="form-inline definewidth m20">
			<button type="button" class="btn btn-success"  onclick="addRule();" >添加</button>
	  	</form>
		<table class="table table-bordered table-hover definewidth m10">
			 <thead>
			    <tr>
			      <th><strong>ID</strong></th>
					<th><strong>理财产品编号</strong></th>
					<th><strong>理财产品名称</strong></th>
					<th><strong>应还时间</strong></th>
					<th><strong>实际还款时间</strong></th>
					<th><strong>状态</strong></th>
					<th><strong>操作</strong></th>
			    </tr>
			   </thead>
			  <?php foreach($auto_repay_list as $info){?>
			  <tr>
				<td><?php echo $info['id'];?></td>
				<td><?php echo $info['borrow_id'];?></td>
				<td>
				<a href="/sys_admin/borrow/borrow_view/<?php echo $info['borrow_id'];?>"><?php echo $info['title'];?></a>
			  </td>
				<td><?php echo date("Y-m-d",$info['each_time']);?></td>
				<td><?php echo $info['repay_time']==0?"未还":date("Y-m-d",$info['repay_time']);?></td>
				<td><?php echo $info['fstatus']==0?"未还":"已还";?></td>
				<td><a href="javascript:removeRule(<?php echo $info['id'];?>);">删除</a></td>
			  </tr>
			  <?php }?>
			  	<tr>
			  	<td colspan="12"  class="invbd_page"><?php echo $this->pagination->create_links();?> 共有<?php echo $auto_repay_count;?>条数据</td>
			  	</tr>
		</table>
</div>
<?php }?>

<div id="adddialog" title="系统提示" style="display:none;">
<div id="addmsg" style="text-align:center;color:red">&nbsp;</div>
理财产品ID：<input type="text" name="borrow_id" id="borrow_id" /> <br /><br />
<div style="text-align:center;">
<input type="button" style="width: 60px; height:24px" value="关闭" onclick="$('#adddialog').dialog('close');"/>
<input type="button" style="width: 60px; height:24px" value="添加" onclick="addsubmitRule();" />
</div>
</div>

<script>
function addRule(){
	$( "#adddialog" ).dialog({
		height:250,
		width:500,
		modal:true, //蒙层（弹出会影响页面大小）
		title:'添加自动还款'
	});
}

function addsubmitRule(){
	if($("#borrow_id").val() == ""){
		$("#adddialog" ).dialog();
		$("#addmsg").html('请输入积分名称');
		return false;
	}

	$.ajax({
		type: "POST",
		url: "/sys_admin/systemset/saveautopay",
		data: "act=add&borrow_id="+$("#borrow_id").val(),
		success: function(ret){
			$("#adddialog" ).dialog();
			$("#addmsg").html(ret.msg);
			setTimeout(function(){
				$("#adddialog" ).dialog("close");
			},3000);
			window.location.reload();
		},
		dataType: "json"
	});	
}

function removeRule(id){
	if(confirm('你确定要删除?'))
	{
		if(id > 0){
			$.ajax({
				type: "POST",
				url: "/sys_admin/systemset/removeautopay",
				data: "act=delete&id="+id,
				success: function(ret){
					window.location.reload();
				},
				dataType: "json"
			});	
		}	
	}	
}
</script>
